package com.example.management.controller;

import com.example.management.pojo.Dormitory;
import com.example.management.service.DormitoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "宿舍")
@RestController
@RequestMapping("/dormitory")
public class DormitoryController {
    @Autowired
    private DormitoryService dormitoryService;

    @ApiOperation("所有宿舍信息")
    @PostMapping("getAll")
    public List<Dormitory> getAllDormitory() {
        return dormitoryService.getAllDormitory();
    }

    @ApiOperation("修改宿舍信息")
    @PostMapping("change")
    public String changeDormitory(@RequestParam Integer number, String buildingTag, String tag,
                                  Integer floor, Integer people) {
        Dormitory dormitory = new Dormitory(number, buildingTag, tag, floor, people);
        return dormitoryService.changeDormitory(dormitory);
    }

    @ApiOperation("删除指定宿舍信息")
    @PostMapping("delete")
    public String deleteDormitory(@RequestParam Integer number) {
        return dormitoryService.deleteDormitory(number);
    }

    @ApiOperation("添加新的宿舍")
    @PostMapping("add")
    public String addDormitory(@RequestParam Integer number, @RequestParam String buildingTag, @RequestParam String tag,
                               @RequestParam Integer floor, @RequestParam Integer people) {
        Dormitory dormitory = new Dormitory(number, buildingTag, tag, floor, people);
        return dormitoryService.addDormitory(dormitory);
    }


}
